home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / DOC2GIH.C < prev    next >
C/C++ Source or Header  |  1992-03-25  |  2KB  |  103 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: doc2gih.c,v 3.26 92/03/25 04:53:29 woo Exp Locker: woo $";
  3. #endif
  4.  
  5. /*
  6.  * doc2gih.c  -- program to convert Gnuplot .DOC format to gnuplot
  7.  * interactive help (.GIH) format.
  8.  *
  9.  * This involves stripping all lines with a leading digit or
  10.  * a leading @, #, or %.
  11.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  12.  *
  13.  * usage:  doc2gih < file.doc > file.gih
  14.  *
  15.  * Original version by David Kotz used the following one line script!
  16.  * sed '/^[0-9@#%]/d' file.doc > file.gih
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21.  
  22. #define MAX_LINE_LEN    256
  23. #define TRUE 1
  24. #define FALSE 0
  25.  
  26. main(argc,argv)
  27. int argc;
  28. char **argv;
  29. {
  30. FILE * infile;
  31. FILE * outfile;
  32.     infile = stdin;
  33.     outfile = stdout;
  34.     if (argc > 3) {
  35.         fprintf(stderr,"Usage: %s infile outfile\n", argv[0]);
  36.         exit(1);
  37.     }
  38.     if (argc >= 2) 
  39.         if ( (infile = fopen(argv[1],"r")) == (FILE *)NULL) {
  40.             fprintf(stderr,"%s: Can't open %s for reading\n",
  41.                 argv[0], argv[1]);
  42.             exit(1);
  43.         }
  44.     if (argc == 3)
  45.         if ( (outfile = fopen(argv[2],"w")) == (FILE *)NULL) {
  46.             fprintf(stderr,"%s: Can't open %s for writing\n",
  47.                 argv[0], argv[2]);
  48.         }
  49.     
  50.     convert(infile,outfile);
  51.     exit(0);
  52. }
  53.  
  54.  
  55. convert(a,b)
  56.     FILE *a,*b;
  57. {
  58.     static char line[MAX_LINE_LEN];
  59.  
  60.     while (fgets(line,MAX_LINE_LEN,a)) {
  61.        process_line(line, b);
  62.     }
  63. }
  64.  
  65. process_line(line, b)
  66.     char *line;
  67.     FILE *b;
  68. {
  69.     static int line_count = 0;
  70.  
  71.     line_count++;
  72.  
  73.     switch(line[0]) {        /* control character */
  74.        case '?': {            /* interactive help entry */
  75.           (void) fputs(line,b); 
  76.           break;        
  77.        }
  78.        case '@': {            /* start/end table */
  79.           break;            /* ignore */
  80.        }
  81.        case '#': {            /* latex table entry */
  82.           break;            /* ignore */
  83.        }
  84.        case '%': {            /* troff table entry */
  85.           break;            /* ignore */
  86.        }
  87.        case '\n':            /* empty text line */
  88.        case ' ': {            /* normal text line */
  89.           (void) fputs(line,b); 
  90.           break;
  91.        }
  92.        default: {
  93.           if (isdigit(line[0])) { /* start of section */
  94.                   /* ignore */
  95.           } else
  96.             fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
  97.                 line[0], line_count);
  98.           break;
  99.        }
  100.     }
  101. }
  102.  
  103.